package top.mccat.common.core.controller.bk;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.mccat.common.annotation.Log;
import top.mccat.common.core.controller.BaseController;
import top.mccat.common.core.domain.AjaxResult;
import top.mccat.common.core.domain.bk.BkCustomer;
import top.mccat.common.enums.BusinessType;
import top.mccat.common.service.IBkCustomerService;
import top.mccat.common.utils.poi.ExcelUtil;
import top.mccat.common.core.page.TableDataInfo;

/**
 * 【客户管理】Controller
 * 
 * @author ruoyi
 * @date 2022-11-06
 */
@RestController
@RequestMapping("/bk/customer")
public class BkCustomerController extends BaseController
{
    @Autowired
    private IBkCustomerService bkCustomerService;

    /**
     * 查询【客户管理】列表
     */
    @PreAuthorize("@ss.hasPermi('bk:customer:list')")
    @GetMapping("/list")
    public TableDataInfo list(BkCustomer bkCustomer)
    {
        startPage();
        List<BkCustomer> list = bkCustomerService.selectBkCustomerList(bkCustomer);
        return getDataTable(list);
    }

    /**
     * 导出【客户管理】列表
     */
    @PreAuthorize("@ss.hasPermi('bk:customer:export')")
    @Log(title = "【客户管理】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BkCustomer bkCustomer)
    {
        List<BkCustomer> list = bkCustomerService.selectBkCustomerList(bkCustomer);
        ExcelUtil<BkCustomer> util = new ExcelUtil<BkCustomer>(BkCustomer.class);
        util.exportExcel(response, list, "【客户管理】数据");
    }

    /**
     * 获取【客户管理】详细信息
     */
    @PreAuthorize("@ss.hasPermi('bk:customer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(bkCustomerService.selectBkCustomerById(id));
    }

    /**
     * 新增【客户管理】
     */
    @PreAuthorize("@ss.hasPermi('bk:customer:add')")
    @Log(title = "【客户管理】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BkCustomer bkCustomer)
    {
        return toAjax(bkCustomerService.insertBkCustomer(bkCustomer));
    }

    /**
     * 修改【客户管理】
     */
    @PreAuthorize("@ss.hasPermi('bk:customer:edit')")
    @Log(title = "【客户管理】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BkCustomer bkCustomer)
    {
        return toAjax(bkCustomerService.updateBkCustomer(bkCustomer));
    }

    /**
     * 删除【客户管理】
     */
    @PreAuthorize("@ss.hasPermi('bk:customer:remove')")
    @Log(title = "【客户管理】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(bkCustomerService.deleteBkCustomerByIds(ids));
    }
}
